package org.emet.dao;

import java.util.HashMap;

public class NonEmptyValueHashMap<K, V> extends HashMap<K, V> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//skip the null -value
	@Override
	public V put(K key, V value) {
		boolean isEmpty = true;
		if (value != null) {
			isEmpty = false;
			if (value.toString().trim().equals("")) {
				isEmpty = true;
			}
		}

		if (!isEmpty)
			return super.put(key, value);
		else
			return value;
	}

	public V put(K key, V value, V nullValue) {
		boolean isEmpty = true;
		if (value != null) {
			isEmpty = false;
			if (value.toString().trim().equals("")) {
				isEmpty = true;
			}
			if (value == nullValue || value.equals(nullValue)) {
				isEmpty = true;
			}
		}

		if (!isEmpty)
			return super.put(key, value);
		else
			return value;
	}
}
